<?php
namespace app\web\controller;

use app\model\Theme; 
use app\model\Lottery; 

class LtWinning extends Base
{
    public function Lt_winning()
    {
/**
 * Created by 底片云
 * Desc:中奖记录
 * User:cbw
 * Date: 2020/11/29
 */

global $_G,$_P;
$params = $_P;
$themeid = isset($params['themeid'])?$params['themeid']:'';//活动id
if($themeid <= 0){
    $themeid = Theme::getDefaultThemenew();
}
$theme = Theme::getThemeById($themeid);
if (!$theme){
    $response = modelShow(40002);
    return_msg($response, '', 'ajax');
}
$config =   Theme::getConfig($themeid);
$system= $_G['system'];
$do = 'Lt_winning';
$ac = !empty($params['ac'])?$params['ac']:'display';
$lr_id = isset($params['lr_id'])?$params['lr_id']:'';
$nickname = isset($params['nickname'])?trim($params['nickname']):'';
$start_day = isset($params['createtime']['start'])?$params['createtime']['start']:time();
$end_day = isset($params['createtime']['end'])?$params['createtime']['end']:time();
$page_index = max(1,intval($params['page']));
$page_size = 10;
$page_start = ($page_index-1)*$page_size;
$receive_list = getReceiveTodoAction();//领奖操作数组
$lottery_items_total = intval(db_find("select count(*) as cnt from".tablename(t_lottery))['cnt']);//奖项数量
if ($ac=='display'){
    $page_total = intval(db_find("select count(*) as cnr from ".tablename(t_lot_record))['cnt']);
    $list = Lottery::getLotteryReceive($themeid,$nickname,'','',$page_start,$page_size);
    $pager = pagination($page_total,$page_index,$page_size);
}
if ($ac=='search'){
    if ($start_day==$end_day){
        $nickname = '%'.$nickname.'%';
        $list = Lottery::getLotteryReceive($themeid,$nickname,'','',$page_start,$page_size);
    }else{
        $list = Lottery::getLotteryReceive($themeid,$nickname,$start_day,$end_day,$page_start,$page_size);
    }
}
if($ac=='prize' && $lr_id){
    $response = modelShow(40000);
    $receive_item = Lottery::getLtRecordByLrId($lr_id);
    if ($receive_item){
        $data = ['status'=>3];
        $update_item = Lottery::updateLtRecordByLrId($lr_id,$data);
        if ($update_item){
            return modelShow(200);
        }
    }
    return_msg($response, '', 'ajax');
}
$total = count($list);
$return_clicent = get_defined_vars();
return view('/lt_winning', $return_clicent);
}
}